package org.teststack.restAssured;

import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.teststack.utils.ReadConf.getHost;

public class login {



    public static void login() {
        String host = getHost();
        String url = host + "/api/v1/user/login";

        //定义多个参数，hashmap定义kv格式参数
//        Map<String, String> para = new HashMap<String, String>();
//        para.put("mail","794666918@qq.com");
//        para.put("pwd","123456");
        given().
                headers("Content-Type", "application/json").
//                params(para).         //请求带参
        body("{\"mail\":\"794666918@qq.com\",\"pwd\":\"123456\"}\n").  //json请求
                when().
                post(url).
                then().
                statusCode(200).
                body("code", equalTo(0)).
                body("msg", equalTo(null)).
                log().all();
    }


    public static void detail(String id,String title) {
        String host = getHost();
        String url = host + "/api/v1/product/detail";

        //定义多个参数，hashmap定义kv格式参数
        Map<String, String> para = new HashMap<String, String>();
        para.put("id", id);
        para.put("title", title);
        given().

                params(para).         //请求带参

                when().
                get(url).
                then().
                statusCode(200).
                body("code",equalTo(0)).
                body("msg",equalTo(null)).
                log().all();
    }
}
